package org.learn.intermediate.com.exercise;
//插队join
public class ThreadMethodExercise {
    public static void main(String[] args) {
        T t = new T();
        Thread thread = new Thread(t);
        //
        int count = 1;
        while(true) {
            System.out.println("hi" + count);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ++count;
            if(count == 6){
                thread.start();
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if(count == 11){
                System.out.println("主线程结束");
                break;
            }
        }



    }
}
class T implements Runnable{
    @Override
    public void run() {
        int count = 1;
        for (int i = 1; i < 11; i++) {
            System.out.println("hello" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("子线程结束");
        return;
    }
}